#include "myrect.h"
#include "screen.h"
#include <QPainter>
#include <QDebug>
#include <QPen>


MyRect::MyRect(QWidget *parent)
    : QWidget(parent)

{
    text = " ";
    hide();
}

void MyRect::setText(QString str)
{
    setFixedSize(text.length()* 15,20);
    text = str;
}

void MyRect::setLocation(qreal x, qreal y)
{
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    const int& ry = y - height() - WIDTHINFO_HEIGHTMARGIN;
    if (ry < 0) {
        this->raise();
    }
    move(x, ((ry < 0) ? y : ry));
    show();
}

void MyRect::paintEvent(QPaintEvent *)
{
    QPainter painter(this);

    painter.setBrush(QBrush(QColor(0, 0, 0, 150)));
    painter.drawRoundRect(rect());
    painter.setPen(QPen(QColor(Qt::white)));
    painter.drawText(rect(), Qt::AlignCenter, text);
}
